<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for functest_modbus_tcp</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>functest_modbus_tcp</b> :
            <span class='pc_cov'>93%</span>
        </h1>
        <h2 class='stats'>
            114 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>106 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>8 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>1 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='stm run hide_run'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='pln'>7</p>
<p class='pln'>8</p>
<p class='pln'>9</p>
<p class='pln'>10</p>
<p class='pln'>11</p>
<p class='stm run hide_run'>12</p>
<p class='stm run hide_run'>13</p>
<p class='stm run hide_run'>14</p>
<p class='stm run hide_run'>15</p>
<p class='stm run hide_run'>16</p>
<p class='stm run hide_run'>17</p>
<p class='stm run hide_run'>18</p>
<p class='stm run hide_run'>19</p>
<p class='stm run hide_run'>20</p>
<p class='stm run hide_run'>21</p>
<p class='stm run hide_run'>22</p>
<p class='pln'>23</p>
<p class='stm run hide_run'>24</p>
<p class='pln'>25</p>
<p class='stm run hide_run'>26</p>
<p class='pln'>27</p>
<p class='stm run hide_run'>28</p>
<p class='stm run hide_run'>29</p>
<p class='stm run hide_run'>30</p>
<p class='pln'>31</p>
<p class='stm run hide_run'>32</p>
<p class='stm run hide_run'>33</p>
<p class='stm run hide_run'>34</p>
<p class='pln'>35</p>
<p class='stm run hide_run'>36</p>
<p class='pln'>37</p>
<p class='stm run hide_run'>38</p>
<p class='stm run hide_run'>39</p>
<p class='pln'>40</p>
<p class='stm run hide_run'>41</p>
<p class='stm run hide_run'>42</p>
<p class='stm run hide_run'>43</p>
<p class='pln'>44</p>
<p class='pln'>45</p>
<p class='stm run hide_run'>46</p>
<p class='stm run hide_run'>47</p>
<p class='stm run hide_run'>48</p>
<p class='pln'>49</p>
<p class='pln'>50</p>
<p class='stm run hide_run'>51</p>
<p class='stm run hide_run'>52</p>
<p class='stm run hide_run'>53</p>
<p class='stm run hide_run'>54</p>
<p class='stm mis'>55</p>
<p class='pln'>56</p>
<p class='stm run hide_run'>57</p>
<p class='pln'>58</p>
<p class='stm run hide_run'>59</p>
<p class='stm run hide_run'>60</p>
<p class='stm run hide_run'>61</p>
<p class='stm run hide_run'>62</p>
<p class='stm run hide_run'>63</p>
<p class='stm mis'>64</p>
<p class='pln'>65</p>
<p class='stm run hide_run'>66</p>
<p class='pln'>67</p>
<p class='stm run hide_run'>68</p>
<p class='stm run hide_run'>69</p>
<p class='stm run hide_run'>70</p>
<p class='pln'>71</p>
<p class='stm run hide_run'>72</p>
<p class='stm run hide_run'>73</p>
<p class='stm run hide_run'>74</p>
<p class='stm run hide_run'>75</p>
<p class='pln'>76</p>
<p class='stm run hide_run'>77</p>
<p class='stm run hide_run'>78</p>
<p class='pln'>79</p>
<p class='stm run hide_run'>80</p>
<p class='stm run hide_run'>81</p>
<p class='pln'>82</p>
<p class='stm run hide_run'>83</p>
<p class='pln'>84</p>
<p class='stm run hide_run'>85</p>
<p class='stm run hide_run'>86</p>
<p class='pln'>87</p>
<p class='stm run hide_run'>88</p>
<p class='stm run hide_run'>89</p>
<p class='stm run hide_run'>90</p>
<p class='pln'>91</p>
<p class='stm run hide_run'>92</p>
<p class='stm run hide_run'>93</p>
<p class='pln'>94</p>
<p class='stm run hide_run'>95</p>
<p class='stm run hide_run'>96</p>
<p class='pln'>97</p>
<p class='stm run hide_run'>98</p>
<p class='pln'>99</p>
<p class='stm run hide_run'>100</p>
<p class='stm run hide_run'>101</p>
<p class='pln'>102</p>
<p class='stm run hide_run'>103</p>
<p class='stm run hide_run'>104</p>
<p class='pln'>105</p>
<p class='pln'>106</p>
<p class='stm run hide_run'>107</p>
<p class='pln'>108</p>
<p class='stm run hide_run'>109</p>
<p class='stm run hide_run'>110</p>
<p class='pln'>111</p>
<p class='stm run hide_run'>112</p>
<p class='stm run hide_run'>113</p>
<p class='pln'>114</p>
<p class='stm run hide_run'>115</p>
<p class='pln'>116</p>
<p class='stm run hide_run'>117</p>
<p class='stm run hide_run'>118</p>
<p class='stm run hide_run'>119</p>
<p class='stm run hide_run'>120</p>
<p class='stm mis'>121</p>
<p class='stm mis'>122</p>
<p class='stm mis'>123</p>
<p class='pln'>124</p>
<p class='stm run hide_run'>125</p>
<p class='pln'>126</p>
<p class='pln'>127</p>
<p class='stm run hide_run'>128</p>
<p class='stm run hide_run'>129</p>
<p class='stm run hide_run'>130</p>
<p class='stm run hide_run'>131</p>
<p class='pln'>132</p>
<p class='stm run hide_run'>133</p>
<p class='pln'>134</p>
<p class='stm run hide_run'>135</p>
<p class='stm run hide_run'>136</p>
<p class='pln'>137</p>
<p class='stm run hide_run'>138</p>
<p class='stm run hide_run'>139</p>
<p class='stm run hide_run'>140</p>
<p class='stm run hide_run'>141</p>
<p class='stm run hide_run'>142</p>
<p class='stm run hide_run'>143</p>
<p class='stm run hide_run'>144</p>
<p class='stm run hide_run'>145</p>
<p class='stm run hide_run'>146</p>
<p class='stm run hide_run'>147</p>
<p class='pln'>148</p>
<p class='stm mis'>149</p>
<p class='stm mis'>150</p>
<p class='stm mis'>151</p>
<p class='pln'>152</p>
<p class='stm run hide_run'>153</p>
<p class='stm run hide_run'>154</p>
<p class='stm run hide_run'>155</p>
<p class='stm run hide_run'>156</p>
<p class='stm run hide_run'>157</p>
<p class='stm run hide_run'>158</p>
<p class='pln'>159</p>
<p class='stm run hide_run'>160</p>
<p class='pln'>161</p>
<p class='stm run hide_run'>162</p>
<p class='stm run hide_run'>163</p>
<p class='stm run hide_run'>164</p>
<p class='pln'>165</p>
<p class='stm par run hide_run'>166</p>
<p class='stm run hide_run'>167</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='com'>#!/usr/bin/env python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># -*- coding: utf-8 -*-</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> Modbus TestKit: Implementation of Modbus protocol in python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> (C)2009 - Luc Jean - luc.jean@gmail.com</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> (C)2009 - Apidev - http://www.apidev.fr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> This is distributed under GNU LGPL license, see license.txt</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>unittest</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>modbus_tk</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus_tcp</span> <span class='key'>as</span> <span class='nam'>modbus_tcp</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>threading</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>struct</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>logging</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>socket</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>utils</span> <span class='key'>as</span> <span class='nam'>utils</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>time</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>sys</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>from</span> <span class='nam'>functest_modbus</span> <span class='key'>import</span> <span class='nam'>TestQueries</span><span class='op'>,</span> <span class='nam'>TestQueriesSetupAndTeardown</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>LOGGER</span> <span class='op'>=</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>utils</span><span class='op'>.</span><span class='nam'>create_logger</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>TestConnection</span><span class='op'>(</span><span class='nam'>unittest</span><span class='op'>.</span><span class='nam'>TestCase</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test the TcpMbap class&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>setUp</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span> <span class='op'>=</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpServer</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span> <span class='op'>=</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpMaster</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>tearDown</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>stop</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testConnectOnSlave</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Setup a slave and check that the master can connect&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>set_timeout</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>open</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#close everything</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>stop</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#and try to reconnect --&gt; should fail</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>open</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>socket</span><span class='op'>.</span><span class='nam'>error</span><span class='op'>,</span> <span class='nam'>message</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testConnectionErrorNoTimeoutDefined</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that an error is raised on connection error&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>master</span> <span class='op'>=</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpMaster</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>master</span><span class='op'>.</span><span class='nam'>open</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>socket</span><span class='op'>.</span><span class='nam'>error</span><span class='op'>,</span> <span class='nam'>message</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadBlock</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Add 1 block on the slave and let&#39;s the master running the values&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>slave</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>add_slave</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>slave</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>slave</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>range</span><span class='op'>(</span><span class='num'>100</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>open</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>100</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>stop</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testCleanConnections</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that the server is cleaning closed connections&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>masters</span> <span class='op'>=</span> <span class='op'>[</span><span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpMaster</span><span class='op'>(</span><span class='op'>)</span> <span class='key'>for</span> <span class='nam'>i</span> <span class='key'>in</span> <span class='nam'>xrange</span><span class='op'>(</span><span class='num'>10</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>m</span> <span class='key'>in</span> <span class='nam'>masters</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>m</span><span class='op'>.</span><span class='nam'>open</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>m</span> <span class='key'>in</span> <span class='nam'>masters</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>m</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>5.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>_sockets</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>TcpTestQueries</span><span class='op'>(</span><span class='nam'>TestQueries</span><span class='op'>,</span> <span class='nam'>unittest</span><span class='op'>.</span><span class='nam'>TestCase</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test the modbus protocol over TCP communication&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_get_server</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpServer</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_get_master</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpMaster</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>TestTcpSpecific</span><span class='op'>(</span><span class='nam'>TestQueriesSetupAndTeardown</span><span class='op'>,</span> <span class='nam'>unittest</span><span class='op'>.</span><span class='nam'>TestCase</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_get_server</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpServer</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_get_master</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>modbus_tcp</span><span class='op'>.</span><span class='nam'>TcpMaster</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadWithWrongFunction</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;check that an error is raised where reading on 2 consecutive blocks&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertRaises</span><span class='op'>(</span><span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusFunctionNotSupportedError</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>55</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bad_query</span> <span class='op'>=</span> <span class='nam'>struct</span><span class='op'>.</span><span class='nam'>pack</span><span class='op'>(</span><span class='str'>&quot;&gt;HHHBH&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>55</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>send</span><span class='op'>(</span><span class='nam'>bad_query</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testMultiThreadAccess</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;check that the modbus call are thread safe&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>slaves</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>slaves</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>add_slave</span><span class='op'>(</span><span class='num'>11</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>slaves</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>add_slave</span><span class='op'>(</span><span class='num'>12</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>Queue</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>q</span> <span class='op'>=</span> <span class='nam'>Queue</span><span class='op'>.</span><span class='nam'>Queue</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>s</span> <span class='key'>in</span> <span class='nam'>slaves</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>s</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;a&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>set_val</span><span class='op'>(</span><span class='nam'>self_</span><span class='op'>,</span> <span class='nam'>slaves</span><span class='op'>,</span> <span class='nam'>q</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>LOGGER</span><span class='op'>.</span><span class='nam'>debug</span><span class='op'>(</span><span class='str'>&quot;set_val started&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>id</span> <span class='op'>=</span> <span class='num'>11</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>i</span> <span class='key'>in</span> <span class='nam'>xrange</span><span class='op'>(</span><span class='num'>50</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>s</span> <span class='key'>in</span> <span class='nam'>slaves</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>s</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;a&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span><span class='op'>*</span><span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self_</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='nam'>id</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>id</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>id</span> <span class='op'>&gt;</span> <span class='num'>12</span><span class='op'>:</span> <span class='nam'>id</span> <span class='op'>=</span> <span class='num'>11</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#time.sleep(0.2)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>Exception</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>LOGGER</span><span class='op'>.</span><span class='nam'>error</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>q</span><span class='op'>.</span><span class='nam'>put</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>threads</span> <span class='op'>=</span> <span class='op'>[</span><span class='nam'>threading</span><span class='op'>.</span><span class='nam'>Thread</span><span class='op'>(</span><span class='nam'>target</span><span class='op'>=</span><span class='nam'>set_val</span><span class='op'>,</span> <span class='nam'>args</span><span class='op'>=</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>slaves</span><span class='op'>,</span> <span class='nam'>q</span><span class='op'>)</span><span class='op'>)</span> <span class='key'>for</span> <span class='nam'>i</span> <span class='key'>in</span> <span class='nam'>xrange</span><span class='op'>(</span><span class='num'>5</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>t</span> <span class='key'>in</span> <span class='nam'>threads</span><span class='op'>:</span> <span class='nam'>t</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>LOGGER</span><span class='op'>.</span><span class='nam'>debug</span><span class='op'>(</span><span class='str'>&quot;all threads have been started&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>t</span> <span class='key'>in</span> <span class='nam'>threads</span><span class='op'>:</span> <span class='nam'>t</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>LOGGER</span><span class='op'>.</span><span class='nam'>debug</span><span class='op'>(</span><span class='str'>&quot;all threads have done&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>q</span><span class='op'>.</span><span class='nam'>empty</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteSingleCoilInvalidValue</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check taht an error is raised when writing a coil with an invalid value&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>_send</span><span class='op'>(</span><span class='nam'>struct</span><span class='op'>.</span><span class='nam'>pack</span><span class='op'>(</span><span class='str'>&quot;&gt;HHHBBHH&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>6</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>response</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>_recv</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>response</span><span class='op'>,</span> <span class='nam'>struct</span><span class='op'>.</span><span class='nam'>pack</span><span class='op'>(</span><span class='str'>&quot;&gt;HHHBBB&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>+</span><span class='num'>128</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>exit</span><span class='key'>if</span> <span class='nam'>__name__</span> <span class='op'>==</span> <span class='str'>&#39;__main__&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>unittest</span><span class='op'>.</span><span class='nam'>main</span><span class='op'>(</span><span class='nam'>argv</span> <span class='op'>=</span> <span class='nam'>unittest</span><span class='op'>.</span><span class='nam'>sys</span><span class='op'>.</span><span class='nam'>argv</span> <span class='op'>+</span> <span class='op'>[</span><span class='str'>&#39;--verbose&#39;</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
